<?php
// ------------------------------------------------------------------------
// |@Author       : Jarmin <edshop@qq.com>
// |@----------------------------------------------------------------------
// |@Date         : 2023-05-09 15:51:57
// |@----------------------------------------------------------------------
// |@LastEditTime : 2023-05-25 18:40:50
// |@----------------------------------------------------------------------
// |@LastEditors  : Jarmin <jarmin@ladmin.cn>
// |@----------------------------------------------------------------------
// |@Description  : 
// |@----------------------------------------------------------------------
// |@FilePath     : User.php
// |@----------------------------------------------------------------------
// |@Copyright (c) 2023 http://www.ladmin.cn   All rights reserved. 
// ------------------------------------------------------------------------
namespace app\api\validate;

use think\Validate;

class User extends Validate
{
    protected $rule =   [
        'name'                => 'require|max:50',
        'username'            => 'require|max:50|unique:user',
        'password'            => 'require|max:32',
        'email'               => 'email|max:50|unique:user,email',
        'phone'               => 'mobile|unique:user,phone',
        'dept_id'             => 'require',
        'role_id'             => 'require',
        'ids'                 => 'require|array',
        'passmode'            => 'require',
        'newpassword'         => 'require',
        'repassword'          => 'require|confirm:newpassword',
    ];
    
    protected $message  =   [
        'name.require'         => 'user.name_require',
        'name.max'             => 'user.name_max',
        'username.require'     => 'user.username_require',
        'username.max'         => 'user.username_max',
        'username.unique'      => 'user.username_unique',
        'password.require'     => 'user.password_require',
        'password.max'         => 'user.password_max',
        'email.email'          => 'user.email_email',
        'email.max'            => 'user.email_max',
        'email.unique'         => 'user.email_unique',
        'phone.mobile'         => 'user.phone_mobile',
        'phone.unique'         => 'user.phone_unique',
        'dept_id.require'      => 'user.dept_id_require',
        'role_list.require'    => 'user.role_id_require',
        'ids.require'          => 'user.ids_require',
        'ids.array'            => 'user.ids_array',
        'newpassword.require'  => 'user.newpassword_require',
        'repassword.require'   => 'user.repassword_require',
        'repassword.confirm'   => 'user.repassword_confirm',
    ];

    // token 验证场景定义
    public function sceneToken()
    {
    	return $this->only(['username', 'password'])->remove('username', 'unique');
    }
    
    // add 验证场景定义
    public function sceneSaveAdd()
    {
    	return $this->only(['name', 'username', 'dept_id', 'role_list', 'password', 'email', 'phone']);
    }

    // edit 验证场景定义
    public function sceneSaveEdit()
    {
    	return $this->only(['name','username', 'dept_id', 'role_list', 'email', 'phone']);
    }

    // remove 验证场景定义
    public function sceneRemove()
    {
    	return $this->only(['ids']);
    }
    
    // reset 验证场景定义
    public function sceneReset()
    {
    	return $this->only(['password', 'newpassword', 'repassword']);
    }

    // reset 验证场景定义
    public function sceneResetBatch()
    {
    	return $this->only(['newpassword', 'repassword']);
    }
}